// File EntityManager.cpp
//
// Purpose: Singleton class to handle the  management of Entities.
//
// Author : Bryson King (edited)
// Original Code Provided by: Mat Buckland 2002 (fup@ai-junkie.com)
// Date : 18 March 2013
// --------------------------------------------------------------
#define DEBUG_SECTION
//#pragma warning (disable:4786)

#include "EntityManager.h"

#include <map>

#include "BaseGameEntity.h"

//--------------------------- Instance ----------------------------------------
//   this class is a singleton
//-----------------------------------------------------------------------------
CEntityManager* CEntityManager::Instance()
{
	static CEntityManager instance;
	return &instance;
}

//------------------------- GetEntityFromID -----------------------------------
//-----------------------------------------------------------------------------
CBaseGameEntity* CEntityManager::GetEntityFromID(int id) const
{
	//find the entity
	EntityMap::const_iterator ent = m_EntityMap.find(id);

	//During debug, verify that the entity is a member of the map
	#ifdef DEBUG_SECTION
		if (ent !=  m_EntityMap.end())
		std::cout << std::endl << "<CEntityManager::GetEntityFromID>: invalid ID";
	#endif

	return ent->second;
}

//--------------------------- RemoveEntity ------------------------------------
//-----------------------------------------------------------------------------
void CEntityManager::RemoveEntity(CBaseGameEntity* pEntity)
{    
	m_EntityMap.erase(m_EntityMap.find(pEntity->ID()));
} 

//---------------------------- RegisterEntity ---------------------------------
//-----------------------------------------------------------------------------
void CEntityManager::RegisterEntity(CBaseGameEntity* NewEntity)
{
	m_EntityMap.insert(std::make_pair(NewEntity->ID(), NewEntity));
}
